package com.sinosoft.cloud.access.abc.service;


import com.sinosoft.cloud.access.annotations.AccessService;
import com.sinosoft.cloud.access.service.AccessServiceBean;
import com.sinosoft.cloud.access.util.TimeUtil;
import com.sinosoft.cloud.cbs.pol.PolicyPrintService;
import com.sinosoft.cloud.rest.TradeInfo;
import feign.RetryableException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description:1018保单重打业务处理类
 * @Author:zhaoshulei
 * @Date:2017/9/19
 */
@AccessService(name = "abc", transCode = "1018")
public class ContRePrintService extends AccessServiceBean {
    /**
     * 日志管理
     */
    private final Log cLogger = LogFactory.getLog(this.getClass());
    //需要调用的微服务
    /**
     * 保单管理保单打印
     */
    @Autowired
    PolicyPrintService policyPrintService;

    @Override
    public TradeInfo service(TradeInfo msg) {

        //错误信息
        String errorStr = "";
        String errorLog = "";
        long microServiceStart = 0L;
        long microServiceEnd = 0L;
        /**
         * 调用微服务接口
         */
        TradeInfo respTradeInfo = null;
        try {
            cLogger.info("开始调用保单重打微服务！");
            microServiceStart = System.currentTimeMillis();
            respTradeInfo = policyPrintService.service(msg);
            microServiceEnd = System.currentTimeMillis();
            cLogger.info(TimeUtil.getMillis(microServiceStart, microServiceEnd, "保单重打微服务"));
        } catch (RetryableException e) {
            microServiceEnd = System.currentTimeMillis();
            errorStr = getExceptionStr(microServiceStart, microServiceEnd, "保单重打", e);
            return getErrorTradeInfo(errorStr);
        } catch (Exception e) {
            errorStr = getExceptionStr(0L, 0L, "保单重打", e);
            return getErrorTradeInfo(errorStr);
        }
        if (respTradeInfo.hasError()) {
            errorStr = respTradeInfo.getErrorList().get(0).toString();
            errorLog = new StringBuffer().append("调用保单重打微服务失败,原因是：").append(respTradeInfo.getErrorList().toString()).toString();
            return getCheckRuleFailInfo(errorStr, errorLog);
        } else {
            cLogger.info("调用保单重打微服务成功！返回结果是：" + respTradeInfo.toString());
        }
        return respTradeInfo;
    }
}